package com.sq.gulimall.product.web;

import com.sq.gulimall.product.service.SkuInfoService;
import com.sq.gulimall.product.vo.SkuItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.concurrent.ExecutionException;

@Controller
public class ItemController {

    @Autowired
    SkuInfoService skuInfoService;
    /**
     * 展示当前sku的详情
     * @param skuId
     * @return
     */
    @GetMapping("/{skuId}.html")
    public String skuItem(@PathVariable("skuId") Long skuId, Model model) throws ExecutionException, InterruptedException {
       SkuItemVo vo = skuInfoService.item(skuId);

       if(vo != null){
           model.addAttribute("item",vo);
           return "item";
       }else{
           //商品不存在，直接重定向到主页
           return "redirect:http://gulimall.com";
       }

    }
}
